import BaseWidget = require('core/BaseWidget.class');
import Topology = require('CsLibrary/TopologyAlgo/Topology');
import Delaunay = require('CsLibrary/TopologyAlgo/Delaunay');
import Geometry = require('CsLibrary/TopologyAlgo/Geometry');
import THREE = require('vendor/threejs/three.min.js');

export = BaseScene;

class BaseScene extends BaseWidget{
    baseClass = "widget-basescene";
    config;
    template;
    scene;
    camera;
    renderer;

    startup(){
        this.addToDom({
            sceneDiv: this.config.sceneDiv
        });
        this.ready();
        this.initThreeJS();
    }

    addToDom (data) {
        var htmlString = _.template(this.template)(data || {});
        this.setHtml(htmlString, '#mainContainer_horizontal');
    };

    initThreeJS(){
        var scene = new THREE.Scene();
		var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );

		var renderer = new THREE.WebGLRenderer();
	    renderer.setSize( window.innerWidth, window.innerHeight );
        this.domObj.append( renderer.domElement );
        
        var dom = this.domObj;
        function animate() {
			requestAnimationFrame( animate );
            renderer.render( scene, camera );
		}
		animate();
    }

    animate(that) {
        that.renderer.render( that.scene, that.camera );
        requestAnimationFrame( that.animate(that));
    }
}